package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户人群业务相关
 */
@Api(tags = "用户人群管理")
@RestController
@Slf4j
public class UserGroupController {
    @Autowired
    private UserGroupService userGroupService;

    @ApiOperation("人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")
    public Result<PageResult<UserGroupVO>> pageList()
        throws BusinessException{
        log.info("查询人群数据分页列表");
        PageResult<UserGroupVO> pageResult = userGroupService.listUserGroup();
        return new Result<>(pageResult);
    }

    @ApiOperation("保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> save(@RequestBody UserGroupParam param)throws BusinessException
    {
        log.info("保存人群数据:{}",param);
        userGroupService.add(param);
        return Result.success();
    }
    @ApiOperation("人群详情")
    @GetMapping("/admin/basic/userGroup/detail/{id}")
    public Result<UserGroupVO> detail(@PathVariable Integer id) throws BusinessException {
        log.info("查询人群详情:{}",id);
        UserGroupVO userGroupVO = userGroupService.detail(id);
        return new Result<>(userGroupVO);
    }
}
